package cn.element.netty.bytebuf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;

public class TestSlice {

    public static void main(String[] args) {
        ByteBuf buf = ByteBufAllocator.DEFAULT.buffer(10);
        buf.writeBytes(new byte[]{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'});
        TestByteBuf.log(buf);

        // 在切片过程中,没有发生数据复制
        ByteBuf f1 = buf.slice(0, 5);
        f1.retain();
        ByteBuf f2 = buf.slice(5, 5);
        TestByteBuf.log(f1);
        TestByteBuf.log(f2);

        System.out.println("====================");
        buf.release();
        f1.setByte(0, 'b');
        TestByteBuf.log(f1);
        TestByteBuf.log(buf);
        
    }

}
